<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<c:set var="module" value="apiTest"/>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
		<form action="${ctx }/admin/apiTest/save?id=${n.id }" id="detail-form" class="form-horizontal" method="post">
			<div class="form-group">
                 <label class="col-sm-2 control-label">api名称</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="name" value="${n.name }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">描述</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="description" value="${n.description }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">url</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="url" value="${n.url }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">api模块</label>
                 <div class="col-sm-10">
                 	<select name="apiModule.id">
						<c:forEach items="${apiModules}" var="m">
							<option value="${m.id }" ${m.id eq n.apiModule.id ? 'selected' : '' }>${m.name }</option>
						</c:forEach>
					</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">示例url</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="exampleUrl" value="${n.exampleUrl }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">示例返回</label>
                 <div class="col-sm-10">
                 	<textarea name="exampleResponse" class="form-control" >${n.exampleResponse }</textarea>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">请求方式</label>
                 <div class="col-sm-10">
                 	<select class="form-control" name="requestMethod" >
                 		<option value="GET" ${n.requestMethod eq 'GET' ? 'selected' : '' }>GET</option>
                 		<option value="POST" ${n.requestMethod eq 'POST' ? 'selected' : '' }>POST</option>
                 	</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">状态</label>
                 <div class="col-sm-10">
                 	<select class="form-control" name="status" >
                 		<option value="0" ${n.status eq 0 ? 'selected' : '' }>有效</option>
                 		<option value="1" ${n.status eq 1 ? 'selected' : '' }>无效</option>
                 	</select>
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">是否覆盖返回</label>
                 <div class="col-sm-10">
                 	<select class="form-control" name="isOverrideResponse" >
                 		<option value="0" ${n.isOverrideResponse? '' : 'selected' }>否</option>
                 		<option value="1" ${n.isOverrideResponse? 'selected' : '' }>是</option>
                 	</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">返回说明</label>
                 <div class="col-sm-10">
                 	<textarea name="responseRemark" class="form-control" >${n.responseRemark }</textarea>
                 </div>
             </div>	
             <div class="unit">
				<label>参数:</label>
				<button onclick="return add();">增加参数</button>
				<div>
					<table class="table" width="100%" layoutH="138" nowrapTD="false">
						<thead>
							<tr>
								<th align="center" width="100">
									参数名
								</th>
								<th align="center" width="100">
									是否必须
								</th>
								<th align="center" width="100">
									默认值
								</th>
								<th align="center" width="100">
									说明
								</th>
								<th align="center" width="100">
									操作
								</th>
							</tr>
						</thead>
						<tbody id="tbody">
							<tr id="templateTr">
								<td>
									<input type="text" name="names"/>
								</td>
								<td>
									<select name="requires">
										<option value="0">否</option>
										<option value="1">是</option>
									</select>
								</td>
								<td>
									<input type="text" name="defaultValues"/>
								</td>
								<td>
									<textarea style="width:100%;" name="descriptions"></textarea>
								</td>
								<td>
									<button onclick="return _delete(this);">删除</button>
								</td>
							</tr>
							<c:forEach items="${n.apiTestParameters }" var="p">
							<tr>
								<td>
									<input type="text" name="names" value="${p.name }"/>
								</td>
								<td>
									<select name="requires">
										<option value="0" ${p.required ? '' : 'selected'}>否</option>
										<option value="1" ${p.required ? 'selected' : ''}>是</option>
									</select>
								</td>
								<td>
									<input type="text" name="defaultValues" value="${p.defaultValue }"/>
								</td>
								<td>
									<textarea style="width:100%;" name="descriptions">${p.description }</textarea>
								</td>
								<td>
									<button onclick="return _delete(this);">删除</button>
								</td>
							</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
			
        	
		</form>
</div>

<script>
var templateTr = $('#templateTr').html();
$('#templateTr').remove();
function _delete(btn) {
	$(btn).parent().parent().remove();
}

function add() {
	var tbody = $('#tbody');
	tbody.append('<tr>' + templateTr + '</tr>');
	return false;
}
</script>

<%@include file="/common/foot.jsp" %>

</body>
</html>
